#!/bin/bash
# Hehehe cocok untuk berjualan SSH & VPN
# Ingin sekedar ngobrol? Email aja ke satriaajiputra15@gmail.com
echo "--------------------------MEMBUAT AKUN SSH TUNNEL BARU-------------------------"
echo "Jual VPS Murah All Datacenter "
echo "Hub: Satria Aji Putra VII di FB"
echo "     081213918460"
echo -e "                                \e[1;33;44m[ by satria.asia ]\e[0m"
if [ $(id -u) -eq 0 ]; then
        read -p "Isikan username baru: " username
        read -p "Berapa hari akun $username aktif: " expired
        if ! [[ "$expired" =~ ^[0-9]+$ ]] ;
        then exec >&2; echo "ERROR! Ngelindur ya bro? Hanya bisa diisi angka tuh!!"; exit 1
fi
        egrep "^${username}:" /etc/passwd >/dev/null
        if [ $? -eq 0 ]; then
                echo "ERROR! Ternyata akun $username sudah ada di server. Coba lagi!"
                exit 1
        else
                ARI=`</dev/urandom tr -dc a-f0-9 | head -c9`
                useradd -e `date -d "$expired days" +"%Y-%m-%d"` -s /bin/false -M $username &> /dev/null
                echo -e "$ARI\n$ARI\n" | passwd $username &> /dev/null
                [ $? -eq 0 ] && echo -e "SUKSES! --- Login: \e[1;33;44m$username\e[0m --- Password: \e[1;33;44m$ARI\e[0m --- Valid s/d: \e[1;33;44m`date -d "$expired days" +"%d-%b-%Y\e[0m"`" || echo "Gubrak! Gagal bikin user. Mungkin anda kurang ganteng :D"
                echo "-------------------------------------------------------------------------------"
        fi
else
        echo "Hanya root yang bisa menjalankan perintah ini"
        exit 2
fi